package twentytwenty;

/**
 * @Author: Zahi
 * @Description:
 * @Date Created in 2020-12-13 11:33
 * @Modified By:
 */
public class CanConstruct_383 {
    public static void main(String[] args) {
        System.out.println(canConstruct("aa", "bab"));
    }

    public static boolean canConstruct(String ransomNote, String magazine) {
        char [] arr1 = ransomNote.toCharArray();
        char [] arr2 = magazine.toCharArray();
        int start1 = 0;
        int start2 = 0;
        while (start1 < arr1.length){
            while (start2 < arr2.length){
                // 如果是充值的‘-’就直接跳过
                if (arr2[start2] == '-'){
                    start2++;
                }else if (start1 < arr1.length && arr1[start1] == arr2[start2]){
                    // 如果两个相等就不能再用了第一个数组直接加一后一个数组需要重置到第一个但是不能重复用所以
                    // 把用过的arr2中的值置为‘-’
                    arr2[start2] = '-';
                    start1++;
                    start2 = 0;
                }else {
                    start2++;
                }
            }
            // 后一个数组比较完了就退出
            break;
        }
        return start1 == arr1.length;
    }
}
